<template>
  <div>
    <el-card>
      <div class="new">
        <div class="box">
          <div class="a">{{ list.increment_questions }}</div>
          <span>新增试题</span>
        </div>
        <div class="box">
          <div class="a">{{ list.increment_users }}</div>
          <span>新增用户</span>
        </div>
        <div class="box">
          <div class="a" id="a1">{{ list.personal_questions }}</div>
          <span>人均刷题量</span>
        </div>
        <div class="box">
          <div class="a" id="a1">{{ list.total_done_questions }}</div>
          <span>总刷题量</span>
        </div>
        <div class="box">
          <div class="a" id="a2">{{ list.total_questions }}</div>
          <span>总试题量</span>
        </div>
        <div class="box">
          <div class="a" id="a2">{{ list.total_users }}</div>
          <span>总用户量</span>
        </div>
      </div>
    </el-card>
    <el-card>
      <div>
        <div class="box1">整体数据</div>
        <div id="myChart" :style="{ width: '1200px', height: '400px' }"></div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { dataTitle, dataStatistics } from '@/api/showdata.js'
export default {
  data () {
    return {
      list: []
    }
  },
  mounted () {
    this.drawLine()
  },
  created () {
    this.getData()
  },
  methods: {
    async getData () {
      const res = await dataTitle()
      this.list = res.data
    },

    async drawLine () {
      const res = await dataStatistics()
      // 基于准备好的dom，初始化echarts实例
      var myChart = this.$echarts.init(document.getElementById('myChart'))
      // 绘制图表
      myChart.setOption({
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          right: 'right'
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '30',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: res.data
          }
        ]
      })
    }
  }
}
</script>

<style lang="less" scoped>
.new {
  display: flex;
  justify-content: space-around;
  text-align: center;
  .a {
    width: 100px;
    height: 100px;
    line-height: 100px;
    border-radius: 50px;
    border: 2px solid #1691fa;
  }
  #a1{
      border: 2px solid #f86b44;
  }
  #a2{
      border: 2px solid #5ed07f;
  }
}
.box1 {
  margin-left: 35px;
  margin-top: 14px;
  font-size: 22px;
  color: #737373;
}
</style>
